

#ifndef __imageH__
#define __imageH__

#include "data.h"
#include <corona.h>
#include "vector.h"
#include "pixeltype.h"

namespace WtfEngine {
	class Image: public DataObject {
		corona::Image *	mpImage;

		public:
			/// Corona images use RGBA8 format
			typedef WtfGraphics::PixelType::tRGBA8		tPixelBuffer;
			typedef tPixelBuffer::tPixelType			tPixel;

			Image(const StringPool::Entry& sName): DataObject(sName), mpImage(NULL) {};
			~Image() { Destroy(); };

			/// Creates a blank image of the specifed size
			void Create(const iVector2D& vDim);

			/// Reads an image from a file
			void Read(const String& sFile);

			/// Writes the image to a file. Format is decided by the
			/// file extension.
			void Write(const String& sFile);

			/// Returns data buffer (RGBA 32-bit format)
			inline tPixelBuffer::tRef getPixels() {
				return new tPixelBuffer(mpImage->getHeight() * mpImage->getWidth(), mpImage->getPixels());
			};

			inline iVector2D getSize() const {
				return iVector2D(mpImage->getWidth(), mpImage->getHeight());
			};

			static IDataObject * Load(const StringPool::Entry& sName);

		protected:
			void Destroy();

			DATA_LOADABLE(Image, sizeof(Image) + (mpImage
				? (sizeof(corona::Image) + (sizeof(tPixel) * mpImage->getWidth() * mpImage->getHeight())) : 0));
	};
};

#endif
